package com.example.foo.wanquanpay.service;

import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.wanquanpay.dao.WanquanPayLogDao;
import com.example.foo.wanquanpay.model.WanquanPayLog;
import com.example.foo.wanquanpay.query.WanquanPayLogQuery;
import java.time.LocalDateTime;

@org.springframework.stereotype.Service
public class WanquanPayLogService {

    private final WanquanPayLogDao wanquanPayLogDao;

    public WanquanPayLogService(WanquanPayLogDao wanquanPayLogDao) {
        this.wanquanPayLogDao = wanquanPayLogDao;
    }

    // ========== WanquanPayLog ==========

    public PageResult<WanquanPayLog> findWanquanPayLogs(WanquanPayLogQuery fecApiDetailQuery, Pageable pageable) {
        return wanquanPayLogDao.findWanquanPayLogs(fecApiDetailQuery, pageable);
    }

    public WanquanPayLog findWanquanPayLogById(Long id) {
        return wanquanPayLogDao.selectById(id);
    }

    public void createWanquanPayLog(String api, String statusCode, String msg, String json) {
        WanquanPayLog wanquanPayLog = new WanquanPayLog();
        wanquanPayLog.setApi(api);
        wanquanPayLog.setStatusCode(statusCode);
        wanquanPayLog.setMsg(msg);
        wanquanPayLog.setJson(json);

        wanquanPayLog.setCreatedAt(LocalDateTime.now());
        wanquanPayLogDao.insert(wanquanPayLog);
    }

}
